<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>28.手写instanceof</title>
</head>

<body>
  <script>


    // 原生instanceof
    // function Person() {
    // }

    // let p1 = new Person()
    // console.log(p1 instanceof Person);

    // 手写instanceof
    function myInstanceof(leftValue, rightValue) {
      leftValue = leftValue.__proto__
      let right = rightValue.prototype

      while (true) {
        if (leftValue == null) {
          return false
        }
        if (leftValue === right) {
          return true
        }
        leftValue = leftValue.__proto__
      }
    }

    function Person() {
    }
    let p1 = new Person()
    console.log(myInstanceof(p1, Person))


  </script>
</body>

</html>